package com.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.MerchantRole;
import com.shop.mapper.MerchantRoleMapper;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * yyt(MerchantRole)表服务接口
 *
 * @author makejava
 * @since 2020-11-26 11:03:50
 */
@Service
@AllArgsConstructor
public class MerchantRoleService {

    private final MerchantRoleMapper merchantRoleMapper;

    public Rsp getRoleList(PageParam<MerchantRole> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        for (int i = 0; i < pageParam.getOrderParams().length; i++) {
            PageHelper.orderBy(pageParam.getOrderParams()[i]);
        }
        List<MerchantRole> roleList = merchantRoleMapper.getRoleList();
        PageInfo<MerchantRole> pageInfo = new PageInfo<>(roleList);
        return !StringUtils.isEmpty(pageInfo.getList()) ? Rsp.success(pageInfo) : Rsp.fail();
    }

    public MerchantRole getRoleById(Integer id) {
        return merchantRoleMapper.getRoleById(id);
    }

}
